<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
	<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
	<title>考勤补漏管理</title>
	<script type="text/javascript" src="../../js/boot.js"></script>
</head>

<body>
	<div class="mini-splitter" style="width: 100%; height: 100%;">
		<div size="240" showCollapseButton="true">
			<div class="mini-fit">
				<ul id="pageTree" class="mini-tree" style="width: 100%;" showTreeIcon="true" allowDrag="true" allowDrop="true" textField="departName"
					idField="departID" resultAsTree="false">
				</ul>
			</div>
		</div>

		<div showCollapseButton="true">
			<fieldset id="fd1" style="width: 97%; margin-bottom: 10px;">
				<legend><span>查询条件</span></legend>
				<div id="queryForm" class="fieldset-body">
					<table class="form-table" border="0" cellpadding="0" cellspacing="0">
						<tr>
							<td class="form-label">
								<span>姓名：</span>
								<div id="txtUserID" class="mini-autocomplete" style="width:150px;" popupWidth="200" textField="userName" valueField="userID">
									<div property="columns">
										<div header="姓名" field="userName" width="40"></div>
										<div header="编号" field="workNo"></div>
									</div>
								</div>
								<input id="comUserID" class="mini-combobox" textField="userName" valueField="userID" style="width: 150px">
								<span>申报状态：</span>
								<input name="status" class="mini-combobox" textField="text" valueField="id" data="CONST.get('submitState')"
									style="width: 150px">
								<input name="orderby" value="deviceTime,desc" class="mini-hidden" />
								<a style="margin: 0 0 0 0;" class="mini-button" iconCls="icon-search" onclick="search()">查询</a>
								<a class="mini-menubutton " menu="#popupMenu">编辑</a>
								<ul id="popupMenu" class="mini-menu" style="display:none;">
									<li onclick="doEdit('add')">新增</li>
									<li onclick="doEdit('update')">修改</li>
									<li onclick="doDelete()">删除</li>
								</ul>
								<a class="mini-menubutton " menu="#popupMenu2">审批</a>
								<ul id="popupMenu2" class="mini-menu" style="display:none;">
									<li iconCls="icon-search" onclick="checkAction('pass')">通过</li>
									<li iconCls="icon-ok" onclick="checkAction('nopass')">不通过</li>
								</ul>
							</td>
						</tr>
					</table>
				</div>
			</fieldset>

			<div class="mini-fit">
				<div id="datagrid" class="mini-datagrid" style="width:100%;height:100%;" pageSize="20" idField="instID" allowResize="true" multiSelect="true">
					<div property="columns">
						<div type="indexcolumn" width="20"></div>
						<div type="checkcolumn" width="20"></div>
						<div field="departName" headerAlign="center" width="80">部门名称</div>
						<div field="workNo" headerAlign="center" width="80">工号</div>
						<div field="userName" headerAlign="center" width="80">姓名</div>
						<div field="deviceTime" dateFormat="yyyy-MM-dd HH:mm:ss" headerAlign="center" width="80">考勤补漏时间</div>
						<div field="supplyRemark" headerAlign="center" width="160">申请说明</div>
						<div field="checkUserName" headerAlign="center" width="80">审核人姓名</div>
						<div field="status" headerAlign="center" renderer="onStatusRenderer" width="40">审核状态</div>
					</div>
				</div>
			</div>
		</div>
	</div>

	<div id="detailWin" class="mini-window" style="width:800px;height:270px;" showMaxButton="true" showCollapseButton="true" showShadow="true"
		showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true">
		<fieldset id="fd1" style="width: 97%; margin-bottom: 10px;">
			<div id="detailForm" style="padding:10px;">
				<input name="supplyID" class="mini-hidden" enabled="false">
				<input name="userID" class="mini-hidden">
				<table align="center">
					<tr>
						<td align="right">用户姓名：</td>
						<td align="left"><input name="userName" class="mini-textbox" enabled="false"></td>
						<td align="right">部门名称：</td>
						<td align="left"><input name="departName" class="mini-textbox" enabled="false"></td>
						<td align="right">申请时间：</td>
						<td align="left"><input name="supplyTime" class="mini-datepicker" format="yyyy-MM-dd HH:mm" enabled="false"></td>
					</tr>
					<tr>
						<td align="right">补漏时间：</td>
						<td align="left"><input name="deviceTime" class="mini-datepicker" format="yyyy-MM-dd HH:mm" showTime="true" timeFormat="H:mm:ss"></td>
						<td align="right">申请说明：</td>
						<td align="left" colspan="3"><input name="supplyRemark" class="mini-textbox" width="380"></td>
					</tr>
					<tr>
						<td align="right">审核人：</td>
						<td align="left"><input name="checkUserName" class="mini-textbox" enabled="false"></td>
						<td align="right">审核时间：</td>
						<td align="left"><input name="checkTime" class="mini-datepicker" format="yyyy-MM-dd HH:mm" enabled="false"></td>
						<td align="right">审核状态：</td>
						<td align="left"><input name="status" class="mini-combobox" data="CONST.get('submitState')" enabled="false"></td>
					</tr>
					<tr>
						<td align="right">审核备注：</td>
						<td align="left" colspan="3"><input name="checkRemark" class="mini-textbox" width="380"></td>
					</tr>
				</table>
			</div>
			<div property="footer" style="text-align:center;padding:5px;padding-right:15px;">
				<a class="mini-button" iconCls="icon-save" id="saveButton" onClick="saveAction('保存')">保存</a>
				<a class="mini-button" iconCls="icon-save" id="submitButton" onClick="saveAction('提交')">提交</a>
				<a class="mini-button" iconCls="icon-cancel" onClick="cancel()">取消</a>
			</div>
		</fieldset>
	</div>

</body>

<script type="text/javascript">

	var onPassState = CONST.get("submitState");

	miniInit();

	var userID = null;
	var localUser = mini.decode(localStorage.getItem('user'));
	if (localUser == null) {
		alert("你还没有登录，请先登录再操作...");
	}
	// 如果是普通用户，使用下拉选择控件，把本人及本人的手下加载进来
	else {
		userID = localUser.userID;
		if (localUser.roleID == "normalUser") {
			mini.get("txtUserID").setVisible(false);
			var comUserID = mini.get("comUserID");
			comUserID.setName("userID");
			http.get("/day/report/user/biz/list.do", function (page) {
				if (page.data.length > 0) {
					comUserID.setData(page.data);
					comUserID.select(0);
					comUserID.on("valuechanged", function (e) {
						// var user = e.selected;
						search();
					});
				}
			});
		}
		// 如果是平台管理员，使用自动补全控件
		else {
			mini.get("comUserID").setVisible(false);
			var txtUserID = mini.get("txtUserID");
			txtUserID.setName("userID");
			txtUserID.set({
				url: http.getUrl("/user/page.do")
			});
			txtUserID.setValue(localUser.userID);
			txtUserID.setText(localUser.userName);
		}
	}

	var tree = mini.get("pageTree");

	var detailForm = new mini.Form("#detailForm");
	var detailWin = mini.get("detailWin");

	// 加载浅蓝色背景和去除滚动条
	$('.mini-splitter').addClass('bg');
	//$('.fieldset-body-body').addClass('bg');

	tree.url = http.getUrl("/sys/depart/list.do");
	tree.load(tree.url);

	var editNode = null; // 当前编辑的节点
	/*********************************************************
	 * 左侧目录树的鼠标点击事件
	 *********************************************************/
	tree.on("nodedblclick", function (e) {
		// debugger
		editNode = e.node;
		tree.loadNode(editNode);
		if (editNode) {
			// search();
		}
	});

	var txtUserID = mini.get("txtUserID");
	txtUserID.setName("userID");
	txtUserID.set({
		url: http.getUrl("/user/page.do")
	});

	var queryForm = new mini.Form("#queryForm");
	var datagrid = mini.get("datagrid"); // 表定义列表
	datagrid.set({
		url: http.getUrl("/oa/supply/page.do")
	});

	function onStatusRenderer(e) {
		for (var i = 0, l = onPassState.length; i < l; i++) {
			var g = onPassState[i];
			if (g.id == e.value) return g.text;
		}
		return "";
	}

	function search() {
		var data = queryForm.getData(true, false);
		var node = tree.getSelectedNode();
		if (node) {
			data["departID"] = node.departID;
			data["departID_link"] = "like";
		}
		// debugger
		// 如果角色是普通用户
		if (localUser.roleID == "normalUser") {
			data["condition"] = "userID='#userID#' or checkUserID='#userID#'";
		}
		data["orderby"] = "submitTime,desc";
		datagrid.load(data, null, miniui.showLoadErrorMessageBox);
	}

	/*********************************************************
	 * 操作方法
	 *********************************************************/
	function doEdit(type) {
		// debugger
		if (type == 'add') {
			if (localUser == null && localUser.userID == null) {
				alert("你还没有登录");
				return;
			}
			detailWin.setTitle("新增");
			detailForm.reset();
			var d = new Date();
			var data = {
				"departName": localUser.departName,
				"supplyTime": d,
				"userID": localUser.userID,
				"userName": localUser.userName,
				"status": 0
			};
			detailForm.setData(data);
			mini.get("saveButton").setEnabled(true);
			mini.get("submitButton").setEnabled(true);
		} else {
			if (datagrid.getSelected() == undefined) {
				mini.alert("请先选择要编辑的数据!", "提示", null);
				return;
			}
			var row = datagrid.getSelected();
			var saveButton = mini.get("saveButton");
			var submitButton = mini.get("submitButton");
			if (row.status == 1) {
				saveButton.setEnabled(false);
				submitButton.setEnabled(false);
			} else {
				saveButton.setEnabled(true);
				submitButton.setEnabled(true);
			}
			detailWin.setTitle("修改");
			detailForm.setData(datagrid.getSelected());
		}
		detailWin.showAtPos('center', 'middle');
	}

	function saveAction(type) {
		miniui.mask("数据保存中...");
		var data = detailForm.getData(true, false);
		if (type == '提交') {
			data.status = 6;
		} else {
			data.status = 0;
		}
		http.post("/oa/supply/save.do", data, function (page) {
			mini.unmask();
			detailWin.hide();
			if (page.success) {
				miniui.showSuccessTip("保存成功");
				datagrid.reload();
			} else {
				miniui.showErrorMessageBox(page.message);
			}
		});
	}

	function cancel() {
		detailWin.hide();
	}

	function doDelete() {
		if (datagrid.getSelected()) {
			mini.confirm("确定要删除选中的记录吗？", "确定？",
				function (action) {
					if (action == "ok") {
						var row = datagrid.getSelected();
						if (userID != row.userID) {
							miniui.showErrorMessageBox("对不起，你不能删除别人申请的记录！");
							return;
						}
						if (row.status == 1) {
							miniui.showErrorMessageBox("对不起，已经通过的申请不能删除！");
							return;
						}
						var data = {
							"supplyID": row.supplyID
						};
						http.post("/oa/supply/delete.do", data, function (page) {
							if (page.success) {
								miniui.showSuccessTip("删除成功");
								datagrid.removeRow(row);
							} else {
								miniui.showErrorMessageBox(page.message);
							}
						});
					}
				});
		} else {
			miniui.showErrorMessageBox("请先选择要删除的记录！");
		}
	}

	function checkAction(type) {
		if (localUser == null && localUser.userID == null) {
			alert("你还没有登录");
			return;
		}
		var userID = localUser.userID;
		var status = 1;
		if (type == 'pass') {
			status = '1';
		} else {
			status = '2';
		}
		miniui.mask("数据保存中...");
		var list = datagrid.getSelecteds();
		if (list.length == 0) {
			miniui.showErrorMessageBox("请先选择要审批的数据...");
			return;
		}
		var ids = common.getListKeys(list, "supplyID");
		var data = {
			"status": status,
			"userID": userID,
			"ids": ids
		}
		http.post("/oa/supply/check.do", data, function (page) {
			mini.unmask();
			if (page.success) {
				miniui.showSuccessTip("保存成功");
				datagrid.reload();
			} else {
				miniui.showErrorMessageBox(page.message);
			}
		});
	}

</script>

</html>